home *** CD-ROM | disk | FTP | other *** search
/ Top 200 Programs / Top 200 Programs.iso / Bob8 / THOMPSON / LIBERTY / PRODUCT / TUTORIAL.EXE / WK5HW1.TXT < prev    next >
Text File  |  1996-03-27  |  5KB  |  161 lines

  1. Week 5 Homework Assignment
  2. Liberty BASIC programming course
  3. Copyright 1996 Shoptalk Systems
  4. All Rights Reserved
  5.  
  6. More on Programming Graphics
  7. ==============================================================================
  8.  
  9. In the first part of week 5 we covered turtle graphics, drawing segments,
  10. drawing with color, and displaying text.  Now we will examine the use of
  11. bitmaps in Liberty BASIC.
  12.  
  13. NOTICE: This week's homework includes four bitmap files named LETTER.BMP,
  14. CALL.BMP, BROCHURE.BMP, and SALE.BMP for use in your assignment.
  15.  
  16.  
  17. Using Bitmaps
  18. ==============================================================================
  19.  
  20. In WINDOWS, a bitmap is a rectangular area containing an image.  WINDOWS
  21. supports bitmaps made up of just two colors (black & white), bitmaps made up
  22. of millions of colors, and everything in between.  Anyone can create their
  23. own bitmaps using WINDOWS Paintbrush and save them as *.BMP files.  There
  24. are other ways to create bitmap files, including the use of scanning
  25. equipment to produce an image from paper.  Electronic cameras are also
  26. becoming very popular.
  27.  
  28. Here we will examine Liberty BASIC's commands for loading bitmaps from a
  29. disk file and for displaying bitmaps into a graphics window or graphicbox
  30. control.
  31.  
  32. Here is a short program that loads one of the bitmaps that comes with
  33. Liberty BASIC and displays it in a graphics window:
  34.  
  35.     'open a graphics window
  36.     open "Display a bitmap" for graphics as #bitmap
  37.  
  38.     'load a bmp file, calling it "aBitmap"
  39.     loadbmp "aBitmap", "bmp\titlettt.bmp"
  40.  
  41.     'draw the bitmap named aBitmap at position 50, 50 and flush it
  42.     print #bitmap, "drawbmp aBitmap 50 50"
  43.     print #bitmap, "flush"
  44.  
  45.     input r$
  46.  
  47. The LOADBMP statement is used to load the bitmap "bmp\titlettt.bmp" into
  48. memory.  Liberty BASIC gives this bitmap the name "aBitmap" ("aBitmap"
  49. is NOT the filename of the bitmap file).  See how this is used when
  50. sending the DRAWBMP command to the graphics window.
  51.  
  52. We can combine drawn graphics and bitmaps.  Here is a small program that
  53. combines a drawn spiral and a bitmap file.
  54.  
  55.     'combine graphics
  56.     open "Draw combined graphics" for graphics as #draw
  57.  
  58.     'draw a spiral
  59.     print #draw, " home ; down"
  60.     for x = 1 to 100
  61.         print #draw, "turn 91 ; go "; x * 2
  62.     next x
  63.  
  64.     'load a bmp file, calling it "aBitmap"
  65.     loadbmp "aBitmap", "bmp\titlettt.bmp"
  66.  
  67.     'display the bitmap named aBitmap at position 100, 100
  68.     print #draw, "drawbmp aBitmap 100 100"
  69.  
  70.     'flush the combined drawing
  71.     print #draw, "flush"
  72.  
  73.     input r$
  74.  
  75. Here's an example of this program that draws in a graphicbox instead of a
  76. graphics window type:
  77.  
  78.     'draw in a graphicbox
  79.     graphicbox #main.draw, 10, 10, 150, 150
  80.     open "Graphicbox example" for dialog as #main
  81.  
  82.     'draw a spiral
  83.     print #main.draw, " home ; down"
  84.     for x = 1 to 100
  85.         print #main.draw, "turn 91 ; go "; x * 2
  86.     next x
  87.  
  88.     'load a bmp file, calling it "aBitmap"
  89.     loadbmp "aBitmap", "bmp\titlettt.bmp"
  90.  
  91.     'display the bitmap named aBitmap at position 100, 100
  92.     print #main.draw, "drawbmp aBitmap 25 45"
  93.  
  94.     'flush the combined drawing
  95.     print #main.draw, "flush"
  96.  
  97.     input r$
  98.  
  99. Using the idea above, a drawn graphic doesn't have to dominate the entire
  100. window.
  101.  
  102.  
  103. Homework assignment
  104. ==============================================================================
  105.  
  106. Write a program called STATUS.BAS that displays a graphic for one of these
  107. four status items:
  108.  
  109.   - initial letter
  110.   - phone call
  111.   - mail information pack
  112.   - sale made
  113.  
  114. A dialog box should contain a graphicbox control to display the graphic, a
  115. listbox control to contain a list of the status item, and a statictext
  116. control to instruct the user to select a status item.
  117.  
  118. Four bitmap files have been included with this week's homework assignment.
  119. Their names are LETTER.BMP, CALL.BMP, BROCHURE.BMP, and SALE.BMP.  You
  120. may use these files to display the graphic for each status item.
  121.  
  122. Here is a short program that shows how to use a listbox control:
  123.  
  124. This let's take this idea and add some other controls to the dialog box:
  125.  
  126.  
  127.     'setup some colors
  128.     dim color$(5)
  129.     color$(0) = "red"
  130.     color$(1) = "green"
  131.     color$(2) = "blue"
  132.  
  133.     statictext #main, "Pick a color:", 10, 10, 120, 20
  134.     listbox #main.colors, color$(, [loop], 10, 35, 120, 60
  135.     open "Listbox example" for dialog as #main
  136.  
  137.     'tell the listbox where to branch on a single-click
  138.     print #main.colors, "singleclickselect [colorSelected]"
  139.  
  140.  
  141. [loop]  'wait here for user input
  142.     input r$
  143.     goto [loop]
  144.  
  145. [colorSelected]  'draw spiral in the selected color
  146.  
  147.     print #main.colors, "selection?"
  148.     input #main.colors, selectedColor$
  149.  
  150.     notice "You selected " + selectedColor$
  151.  
  152.     goto [loop]
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.